<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
    <script type="text/javascript" src="/js/jquery-3.3.1.js"></script>
</head>
<body>
账号：<input id="name" name="账号" type="text">
密码：<input id="password" name="密码" type="password">
<button type="button" value="登录" onclick="login()">登录</button>
<script>
    function login(){
        var name = $("#name").val();
        var password = $("#password").val();
        $.ajax({
            url : "/login",
            type : "post",
            // data表示发送的数据
            data : JSON.stringify({
                stuId : name,
                stuPassword : password
            }),

            // 定义发送请求的数据格式为JSON字符串
            contentType : "application/json;charset=UTF-8",
            //定义回调响应的数据格式为JSON字符串,该属性可以省略
            dataType : "json",
            //成功响应的结果
            success : function(data) {
                if (data != null) {
                    console.log(data);
                    alert("登录成功");
                    location.href = "emp.html";
                }else if (data == 0){
                    alert("登陆失败");
                }
            }
        });
    }
</script>
</body>
</html>
